from toolkit_libs.similarity import similarity

# Search the given numpy matrix for similar samples
# 'target' is the index of the target sample
# 'data' is a numpy array representing the set of samples
# 'similarity_measure' is one of {'SMC', 'Jaccard', 'ExtendedJaccard', 'Cosine', 'Correlation' }
def get_similarity2index(target, data, similarity_measure):
    not_target = range(0,target) + range(target+1, data.shape[0]) 
    # Compute similarity between target and all others
    sim = similarity(data[target,:], data[not_target,:], similarity_measure)
    sim = sim.tolist()[0]
    # Tuples of sorted similarities and their indices
    sim_to_index = sorted(zip(sim,not_target))
    return sim_to_index
